package com.demo.util;

import org.apache.commons.codec.binary.Base64;

import java.io.UnsupportedEncodingException;

/**
 * @author sdyang
 * @create 2019-02-21 15:16
 **/
public class Base64Util {

    public static String encode(String data) {
        try {
            return new String(Base64.encodeBase64(data.getBytes()), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static String decode(String base64String) {
        byte[] data = new byte[0];

            data = Base64.decodeBase64(base64String);

        return new String(data);
    }
}
